package com.nerve.secondhandcar.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.ko.core.domain.support.BaseEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * 平台中的汽车品牌Domain
 * @author 集成显卡
 * @version 2014-10-09 17:26:50
 */
@SuppressWarnings("serial")
@Entity
@Table(name="car_brand")
public class Brand extends BaseEntity {
	
	private String name;        //品牌名称
	private int sort;           //品牌排序，值越大越靠前，默认为0
	private char publicSelect;   //是否放置到首页，默认为0，如果为1，则会在首页的品牌列表中显示出来
	private String firstLetter; //品牌名称的拼音首字母，如“大众”的首字母为 D，方便查找
    
	
	private Brand parent;  //品牌的上级，为null时，则没有上级。如“捷达”品牌是属于“大众”的，那么parent_id就是“大众”对应的id
	private List<Brand> children;
	
	public Brand() {
		super();
	}

	public Brand(Long id){
		this();
		this.setId(id);
	}
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@Column(columnDefinition="int(10) default 0")
	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}
	@Column(columnDefinition="int(1) default 0")
		public char getPublicSelect() {
		return publicSelect;
	}

	public void setPublicSelect(char publicSelect) {
		this.publicSelect = publicSelect;
	}

	public String getFirstLetter() {
		return firstLetter;
	}
	public void setFirstLetter(String firstLetter) {
		this.firstLetter = firstLetter;
	}
	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY,optional=true)
	@JoinColumn(name = "pid")
	public Brand getParent() {
		return parent;
	}
	public void setParent(Brand parent) {
		this.parent = parent;
	}
	
	@JsonIgnore
	@OneToMany(fetch = FetchType.LAZY,mappedBy = "parent",cascade=CascadeType.ALL)
	public List<Brand> getChildren() {
		return children;
	}

	public void setChildren(List<Brand> children) {
		this.children = children;
	}
	
	
}